<?php

	require_once "../../konfigurasi.php";
	
	koneksi_buka();
	
	if(isset($_GET['id'])){
		$id = $_GET['id'];
	}
	
	if(isset($_POST['id'])){
		$id = $_POST['id'];
	}
	
	if(isset($_GET['nis'])){
		$nis = $_GET['nis'];
	}
	
	if(isset($_POST['nis'])){
		$nis = $_POST['nis'];
	}
	
	if(isset($_POST['user_name'])){
		$username = $_POST["user_name"];
	}
	if(isset($_POST['password'])){
		$password = $_POST["password"];
	}
	if(isset($_POST['level'])){
		$level = $_POST["level"];
	}
	if(isset($_POST['operation'])){
		$operation = $_POST["operation"];
	}
	
	if(isset($_GET['operation'])){
		$operation = $_GET["operation"];
	}
	
	$tgl_daftar = date("Y-m-d");
	$wkt = date("H:i:s");
	
	if($operation=="get_text"){
		$q_siswa = mysql_query("select * from siswa where nis='$nis'");
		if($dt_siswa = mysql_fetch_array($q_siswa)) {
			echo $dt_siswa['nama']." (".$dt_siswa['kelas'].")";
		}
	}else if($operation == "add") {
	
		$q = "INSERT INTO user
			(username,password, level) 
			VALUES('$username','$password','$level')";
		$result = mysql_query($q);
		if($result){
			header("Location:../../index.php");
		}else{
			echo 'failed query :'.$q ;
		}
		
		
	}else if($operation == "edit") {
		$result = mysql_query("UPDATE member SET 
			username='$userName',
			password='$password',
			level='$level',
			WHERE nis=".$nis);
			
		if($result){
			echo 'success';
		}else{
			echo 'failed';
		}
		
		
	}else if($operation == "remove") {
		
		$result = mysql_query("DELETE FROM user WHERE nis=".$nis);
	
		if($result){
			echo 'success';
		}else{
			echo 'failed';
		}
		
	}
?>
